package com.wushi.lenovo.asia5b.app_ui.profile.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.mvp.base.BaseMvpActivity;
import com.mvp.helper.WCallBack;
import com.wushi.lenovo.asia5b.R;
import com.wushi.lenovo.asia5b.app_config.CommonConstant;
import com.wushi.lenovo.asia5b.app_config.UserRepository;
import com.wushi.lenovo.asia5b.app_di.APPComponentFactory;
import com.wushi.lenovo.asia5b.app_di.login.mvpview.ProfileActivityView;
import com.wushi.lenovo.asia5b.app_di.login.presenter.ProfileActivityPresenter;
import com.wushi.lenovo.asia5b.app_event.LoginEvent;
import com.wushi.lenovo.asia5b.app_model.other.UserInfo;
import com.wushi.lenovo.asia5b.app_ui.other.dialog.CancelSureDialog;

import org.greenrobot.eventbus.EventBus;

import butterknife.OnClick;
import timber.log.Timber;

/**
 * Created by zhangyuncai on 2018/12/11.
 */
public class ProfileActivity extends BaseMvpActivity<ProfileActivityView, ProfileActivityPresenter> implements ProfileActivityView {
    @Override
    protected int getLayoutId() {
        return R.layout.activity_profile;
    }

    @Override
    protected void constructComponent() {
        APPComponentFactory.getAppBaseComponent().inject(this);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();

        initData();

        initEvent();
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {

    }

    @OnClick({
            R.id.tv_profile_infomation,
            R.id.tv_addressbook,
            R.id.tv_mobilenumber,
            R.id.tv_loginpassword,
            R.id.tv_paymentpassword,
            R.id.tv_language,
            R.id.tv_logout,
            R.id.tv_notification})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_notification: {

            }
            break;
            case R.id.tv_profile_infomation: {
                startActivity(new Intent(this, PersonalInfoActivity.class));
            }
            break;
            case R.id.tv_addressbook: {
                startActivity(new Intent(this, ShipAddressActivity.class));
            }
            break;
            case R.id.tv_mobilenumber: {
                startActivity(new Intent(this, MobileInfoActivity.class));
            }
            break;
            case R.id.tv_loginpassword: {
                startActivity(new Intent(this, ChangeLoginPassActivity.class));
            }
            break;
            case R.id.tv_paymentpassword: {
                if (UserInfo.getUserInfo().getHas_pay_pass()) {
                    startActivity(new Intent(this, CheckPayPassActivity.class));
                } else {
                    startActivity(new Intent(this, FirstPayPassActivity.class));
                }
            }
            break;
            case R.id.tv_language: {
                startActivity(new Intent(this, SetLanguageActivity.class));
            }
            break;
            case R.id.tv_logout: {
                new CancelSureDialog(this, R.string.logout, R.string.cancel, R.string.profile_logout_notice, new WCallBack() {
                    @Override
                    public void callback(Object o) {
                        getPresenter().logout();
                    }
                }).show();


            }
            break;
            default:
                break;
        }

    }


    @Override
    public void logout() {
        UserRepository.setUserInfo(null);
        Timber.d("--->>>>>>>>---主动退出");
        //这里是唯一发布退出的渠道
        EventBus.getDefault().post(new LoginEvent(CommonConstant.LOGOUT_SUCCESS));
        finish();
    }
}
